<?php

namespace App\Http\Middleware;

use App\Larqq;
use Closure;

class CheckQq
{
    private $qq;
    public function __construct()
    {
        $this->qq = new Larqq();
    }

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $host = "http://".$request->server('HTTP_HOST').$request->server('REQUEST_URI');
        $res = $this->qq->all();
        $qqlist = [];
        foreach ($res as $v){
            $qqlist[]=$v->lar_qq_href;
        }
        if(in_array($host,$qqlist)){
            return redirect('/');
        }
        return $next($request);

    }
}
